package com.fengxing.ams.web.facade.mouble.notification;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

public interface INotificationDAO extends PagingAndSortingRepository<NotificationVO, Integer>, JpaSpecificationExecutor<NotificationVO>  {

	@Query(value="select count(1) from zyt_notification where user_id=:user_id and readed='未读'", nativeQuery=true)
	Long queryUnread(@Param("user_id")Long userId);

	@Query(value="select * from zyt_notification where user_id=:user_id and readed='未读' and created_date >= :time", nativeQuery=true)
	List<NotificationVO> findNew(@Param("user_id")Long userId, @Param("time")Date time);

	@Modifying
	@Query(value="update zyt_notification set readed='已读' where user_id=:user_id and readed='未读'", nativeQuery=true)
	void updateReaded(@Param("user_id")Long userId);

	@Query(value="select * from zyt_notification where user_id=:user_id and readed='未读'", nativeQuery=true)
	List<NotificationVO> queryRureadList(@Param("user_id")Long userId);

	@Modifying
	@Query(value="update zyt_notification set readed='已读' where id in (:id) and user_id=:user_id and readed='未读'", nativeQuery=true)
	void updateReaded(@Param("user_id")Long userId, @Param("id")List<Integer> ids);

}
